<!DOCTYPE html>
<html  class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>PingPangTask-0.1</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <base th:href="@{/}">
        <link rel="stylesheet" th:href="@{/static/css/font.css}">
        <link rel="stylesheet" th:href="@{/static/css/xadmin.css}">
        <script th:src="@{/static/lib/layui/layui.js}" charset="utf-8"></script>
        <script type="text/javascript" th:src="@{/static/js/xadmin.js}"></script>
    </head>
    
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        
                            <form class="layui-form layui-col-space5" id="sreach">
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="开始日" name="startDate" id="start"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input class="layui-input" placeholder="截止日" name="endDaet" id="end"></div>
								<div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="ipport" placeholder="IP" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="name" placeholder="请输入任务名称" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <input type="text" name="purpose" placeholder="备注" autocomplete="off" class="layui-input"></div>
                                <div class="layui-input-inline layui-show-xs-block">
                                    <button class="layui-btn" type="button"  onclick="sreach();">
                                        <i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                                <i class="layui-icon"></i>批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加任务','taskRegist/add?id=-1',400,400)">
                                <i class="layui-icon"></i>添加</button></div>
                        <div class="layui-card-body ">
                            <table class="layui-table layui-form" id="regist">
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <script type="text/javascript" >
    layui.use(['laydate','form','table'],
        function() {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
            
            var table = layui.table;
            //第一个实例
            table.render({
              elem: '#regist',
              height: 312,
              url: 'taskRegist/data', //数据接口
              method:'post',
              contentType: 'application/json; charset=UTF-8',
              //where:JSON.stringify(layui.form.field),
              page: true, //开启分页
              cols: [
            	      [
            	    	{type: 'checkbox',fixed:'left'},
		                {field: 'id', title: 'ID', width:80, sort: true},
		                {field: 'name', title: '注解名称', width:80},
		                {field: 'method', title: '方法名称', width:120},
		                {field: 'ipport', title: '地址', width:180, sort: true},
		                {field: 'purpose', title: '备注', width:80},
		                {field: 'insertDate', title: '插入时间', width: 150},
		                {field: 'updateDate', title: '更新时间', width: 150, sort: true},
		                {field: 'status', title: '状态', width: 80, sort: true,templet:'<div>{{ statusFormat(d.status)}}</div>'},
		                {field: 'right', title: '操作', width: 135, toolbar:"#barDemo"}
                      ]
            	    ]
            });
            
        });

    function sreach(){
    	var param=JSON.stringify(getFormJson($('#sreach')));
    	//alert(param);
    	layui.table.reload("regist", { //此处是上文提到的 初始化标识id
            where: {
            	search:param
            }
        });
    	return false;
    }
    

    //将form中的值转换为键值对。
    function getFormJson(frm) {
        var o = {dosubmit:1};
        var a = $(frm).serializeArray();
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
    
    /*用户-删除*/
    function member_del(id){
        layer.confirm('确认要删除吗？',function(index){
        	
        	  $.ajax({
        		  type: 'POST',
        		  async: false,
        		  dataType:'json',
        		  url:'taskRegist/del',
        		  data:"ids="+id,
        		  success: function(data){
        			  if("S"==data.CODE){
        				  layer.msg('删除成功', {icon: 1});
        				 // window.parent.location.reload();
        				  layui.table.reload("regist", { //此处是上文提到的 初始化标识id
        		                where: {
        		                    //key: { //该写法上文已经提到
        		                        //type: item.type, id: item.id
        		                    //}
        		                }
        		            });
        			  }
        		  },
        		  error : function(errorMsg) {
                      layer.msg(errorMsg,{time:2000,end:function(){
        			  }});
        		  }
        		});
        });
    }

    function delAll (argument) {
     var checkStatus = layui.table.checkStatus('regist').data;
      var ids = [];
      for(var i=0;i<checkStatus.length;i++){
    	  ids.push(checkStatus[i].id);
      }
      layer.confirm('确认要删除吗？',function(index){
          //捉到所有被选中的，发异步进行删除
           $.ajax({
            		  type: 'POST',
            		  async: false,
            		  dataType:'json',
            		  url:'taskRegist/del',
            		  data:"ids="+ids.toString(),
            		  success: function(data){
            			  if("S"==data.CODE){
            				  layer.msg('删除成功', {icon: 1});
            				 // window.parent.location.reload();
            				  layui.table.reload("regist", { //此处是上文提到的 初始化标识id
            		                where: {
            		                    //key: { //该写法上文已经提到
            		                        //type: item.type, id: item.id
            		                    //}
            		                }
            		            });
            			  }
            			  //layer.msg(data.MESSAGE,{time:2000,end:function(){
            			  //}});
            		  },
            		  error : function(errorMsg) {
                          layer.msg(errorMsg,{time:2000,end:function(){
            			  }});
            		  }
            		});
      }); 
    }

   function statusFormat(statu) {
    	var msg="";
        if(0==statu){
        	msg="可执行";
        }else if(1==statu){
        	msg="停用";
        }else if(-1==statu){
        	msg="删除";
        }else{
        	msg=" 未识别 ";
        }
        return msg;
    }  
</script>
        
<script type="text/html" id="barDemo">
	       <button type="button" class="layui-btn" onclick="xadmin.open('编辑','taskRegist/add?id={{d.id}}');">编辑</button>
           <button type="button" class="layui-btn" onclick="member_del('{{d.id}}');">删除</button>
</script>        

</html>